home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.08 Aug 91 / editor4 / editor.cp next >
Encoding:
Text File  |  1991-06-19  |  7.8 KB  |  323 lines  |  [TEXT/MPS ]

  1. #include <UMacApp.h>
  2. #include <UPrinting.h>
  3. #include <UTEView.h>
  4. #include <Fonts.h>
  5. #include <ToolUtils.h>
  6.  
  7. #include "editor.h"
  8.  
  9. // ***** Global constants
  10.  
  11. const OSType kSignature     = 'JLMT';
  12. const OSType kFileType         = 'JL01';
  13. const int    kWindowID        = 1002;    
  14.  
  15. // ***** Class TEditor 
  16.  
  17. pascal TEditor::TEditor(OSType itsMainFileType)
  18. {
  19.     TEditView        *aEditView;
  20.     TBoxView        *aBoxView;
  21.     
  22.     IApplication(itsMainFileType);
  23.  
  24.     if (gDeadStripSuppression)
  25.     {
  26.         aEditView = new TEditView;
  27.         aBoxView  = new TBoxView;
  28.     }
  29. }
  30.  
  31. pascal struct TDocument *TEditor::DoMakeDocument(CmdNumber itsCmdNumber)
  32. {
  33.     TEditDocument* aEditDocument;
  34.     aEditDocument = new TEditDocument;
  35.     FailNIL(aEditDocument);
  36.     return aEditDocument;
  37. }
  38.  
  39. pascal void TEditor::HandleFinderRequest()  {};
  40.  
  41. #ifdef qDebug
  42. pascal void TEditor::IdentifySoftware()
  43. {
  44.     ProgramReport("\pEditor ©J.Langowski/MacTutor May 1991",false);
  45.     inherited::IdentifySoftware();
  46. }
  47. #endif
  48.  
  49.  
  50. // ***** Class TEditDocument 
  51.  
  52. pascal TEditDocument::TEditDocument()
  53. {
  54.     IDocument(kFileType, kSignature, kUsesDataFork,
  55.         !kUsesRsrcFork, !kDataOpen, !kRsrcOpen);
  56.     fSavePrintInfo = true;    // save print info in data fork
  57. }
  58.  
  59. pascal void TEditDocument::DoMakeViews(Boolean forPrinting)
  60. {
  61.     VRect    itsExtent;
  62.     Rect    itsQDExtent;
  63.  
  64.     TBoxView    *aBoxView;
  65.     TEditBox    *aEditBox;
  66.  
  67.     TWindow    *aWindow;
  68.  
  69.     aWindow = NewTemplateWindow(kWindowID,this);
  70.     FailNIL(aWindow);
  71.  
  72.     aWindow->SimpleStagger(kStdStaggerAmount, kStdStaggerAmount, &gStdStaggerCount);
  73.  
  74.     fEditView = (TEditView*) aWindow->FindSubView('scrl');
  75.     FailNIL(fEditView);
  76.     fEditView->IEditView(this);
  77.     
  78.     aWindow->Show(true,false); // so view can be focused
  79.     
  80.     if (fEditView->Focus())  // must focus for ViewToQDRect
  81.     {
  82.         aBoxView = (TBoxView*) aWindow->FindSubView('tx01');
  83.         FailNIL(aBoxView);
  84.         aBoxView->GetFrame(&itsExtent);
  85.         fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
  86.         aEditBox = new TEditBox(&itsQDExtent,aBoxView,this);
  87.         FailNIL(aEditBox);
  88.         fEditView->AddShape(aEditBox);
  89.         
  90.         aBoxView = (TBoxView*) aWindow->FindSubView('tx02');
  91.         FailNIL(aBoxView);
  92.         aBoxView->GetFrame(&itsExtent);
  93.         fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
  94.         aEditBox = new TEditBox(&itsQDExtent,aBoxView,this);
  95.         FailNIL(aEditBox);
  96.         fEditView->AddShape(aEditBox);
  97.         
  98.         aWindow->SetTarget(aBoxView);  //  just for testing, set to view no. 2
  99.     
  100.         aBoxView = (TBoxView*) aWindow->FindSubView('tx03');
  101.         FailNIL(aBoxView);
  102.         aBoxView->GetFrame(&itsExtent);
  103.         fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
  104.         aEditBox = new TEditBox(&itsQDExtent,aBoxView,this);
  105.         FailNIL(aEditBox);
  106.         fEditView->AddShape(aEditBox);
  107.         
  108.         aBoxView = (TBoxView*) aWindow->FindSubView('tx04');
  109.         FailNIL(aBoxView);
  110.         aBoxView->GetFrame(&itsExtent);
  111.         fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
  112.         aEditBox = new TEditBox(&itsQDExtent,aBoxView,this);
  113.         FailNIL(aEditBox);    
  114.         fEditView->AddShape(aEditBox);
  115.     }
  116.  
  117. }
  118.  
  119. pascal void TEditDocument::DoNeedDiskSpace(long *dataForkBytes, long *rsrcForkBytes)
  120. {
  121. }
  122.  
  123. pascal void TEditDocument::DoRead(short aRefNum, Boolean rsrcExists, Boolean forPrinting)
  124. {
  125. }
  126.  
  127. pascal void TEditDocument::DoWrite(short aRefNum, Boolean makingCopy)
  128. {
  129. }
  130.  
  131. pascal void TEditDocument::Free()
  132. {
  133. }
  134.  
  135. #ifdef qDebug
  136. pascal void TEditDocument::Fields(pascal void (*DoToField) (StringPtr fieldName,
  137.                     Ptr fieldAddr, short fieldType, void *link), void *link)
  138. {    
  139.     DoToField("\pTEditDocument", nil, bClass, link);
  140.     DoToField("\pfEditView", (Ptr) &fEditView, bObject, link);
  141.     inherited::Fields(DoToField, link);
  142. }
  143. #endif
  144.  
  145. // *****  Shape class methods
  146.  
  147. pascal TBox::TBox(Rect *itsLocation)
  148.     {      fLocation = *itsLocation;  
  149.         fSelected = false;    }
  150.  
  151. pascal void TBox::DrawShape()
  152. {
  153.     //  add code later for shape selections
  154. }
  155.  
  156. #ifdef qDebug
  157. pascal void TBox::Fields(pascal void (*DoToField) (StringPtr fieldName,
  158.                         Ptr fieldAddr, short fieldType, void *link), void *link)
  159. {
  160.     DoToField("\pTBox", nil, bClass, link);
  161.     DoToField("\pfLocation", (Ptr) &fLocation, bRect, link);
  162.     DoToField("\pfSelected", (Ptr) &fSelected, bBoolean, link);
  163.     DoToField("\pfTagRgn", (Ptr) &fTagRgn, bRgnHandle, link);
  164.     DoToField("\pfTL", (Ptr) &fTL, bRect, link);
  165.     DoToField("\pfTR", (Ptr) &fTR, bRect, link);
  166.     DoToField("\pfBL", (Ptr) &fBL, bRect, link);
  167.     DoToField("\pfBR", (Ptr) &fBR, bRect, link);
  168.     DoToField("\pfT", (Ptr) &fT, bRect, link);
  169.     DoToField("\pfB", (Ptr) &fB, bRect, link);
  170.     DoToField("\pfL", (Ptr) &fL, bRect, link);
  171.     DoToField("\pfR", (Ptr) &fR, bRect, link);
  172.     inherited::Fields(DoToField, link);
  173. }
  174. #endif
  175.  
  176.  
  177. pascal TShape::TShape(Rect *itsLocation) : (itsLocation)
  178. {  
  179.     fPenSize = 1;
  180.     
  181.     for (int i = 0; i<8 ; i++)
  182.         { fPenPat[i]  = qd.black[i];
  183.           fFillPat[i] = qd.gray[i];
  184.         }
  185. }
  186.  
  187. #ifdef qDebug
  188. pascal void TShape::Fields(pascal void (*DoToField) (StringPtr fieldName,
  189.                         Ptr fieldAddr, short fieldType, void *link), void *link)
  190. {
  191.     DoToField("\pTShape", nil, bClass, link);
  192.     DoToField("\pfPenSize", (Ptr) &fPenSize, bInteger, link);
  193.     DoToField("\pfPenPat", (Ptr) &fPenPat, bPattern, link);
  194.     DoToField("\pfFillPat", (Ptr) &fFillPat, bPattern, link);
  195.     inherited::Fields(DoToField, link);
  196. }
  197. #endif
  198.  
  199.  
  200. pascal TEditBox::TEditBox(Rect *itsLocation, 
  201.             TBoxView *itsView, TEditDocument *itsDocument) : (itsLocation)
  202. {    fBoxView = itsView;
  203.     fEditDocument = itsDocument;
  204. }
  205.  
  206. pascal void TEditBox::DrawShape()
  207. {
  208.     VRect    itsExtent;
  209.     Rect    itsQDExtent;
  210.     
  211.     PenNormal();
  212.     fBoxView->GetFrame(&itsExtent);
  213.     fEditDocument->fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
  214.     FrameRect(&itsQDExtent);
  215.  
  216.     inherited::DrawShape();
  217. }
  218.  
  219. #ifdef qDebug
  220. pascal void TEditBox::Fields(pascal void (*DoToField) (StringPtr fieldName,
  221.                         Ptr fieldAddr, short fieldType, void *link), void *link)
  222. {
  223.     DoToField("\pTEditBox", nil, bClass, link);
  224.     DoToField("\pfBoxView", (Ptr) &fBoxView, bObject, link);
  225.     DoToField("\pfEditDocument", (Ptr) &fEditDocument, bObject, link);
  226.     inherited::Fields(DoToField, link);
  227. }
  228. #endif
  229.  
  230. // *****  TBoxView methods
  231.  
  232. pascal struct TCommand *TBoxView::DoMouseCommand(Point *theMouse,
  233.                     EventInfo *info, Point *hysteresis)
  234. {    
  235.     this->GetWindow()->SetTarget(this);
  236.     inherited::DoMouseCommand(theMouse, info, hysteresis);
  237.     return gNoChanges;
  238. }
  239.  
  240. #ifdef qDebug
  241. pascal void TBoxView::Fields(pascal void (*DoToField) (StringPtr fieldName,
  242.                         Ptr fieldAddr, short fieldType, void *link), void *link)
  243. {
  244.     DoToField("\pTBoxView", nil, bClass, link);
  245.     inherited::Fields(DoToField, link);
  246. }
  247. #endif
  248.  
  249.  
  250. // *****  TEditView methods
  251.  
  252. pascal void TEditView::IEditView(TEditDocument *itsDocument)
  253. {
  254.     TStdPrintHandler    *aStdPrintHandler;
  255.     TList                *aList;
  256.     
  257.     aStdPrintHandler = new TStdPrintHandler;
  258.     FailNIL(aStdPrintHandler);
  259.     aStdPrintHandler->IStdPrintHandler
  260.         (nil,this,kSquareDots,kFixedSize,!kFixedSize);
  261.     fPrintHandler = aStdPrintHandler;
  262.     
  263.     fDocument = itsDocument;
  264.     
  265.     aList = NewList();
  266.     fShapeList = aList;
  267. }
  268.  
  269. pascal void TEditView::AddShape(TBox *aBox) 
  270.     {    fShapeList->InsertFirst(aBox);    }
  271.  
  272. pascal void TEditView::DeleteShape()
  273.     {    fShapeList->Delete(fShapeList->First());    }
  274.  
  275. pascal void TEditView::ForEachShapeDo(pascal void (*DoToItem)
  276.             (TObject *item, void *DoToItem_Staticlink),void *DoToItem_Staticlink)
  277. {    fShapeList->Each(DoToItem,DoToItem_Staticlink);    }
  278.  
  279.  
  280. pascal void DrawYourself(TBox *aBox, void *link)
  281.     {    aBox->DrawShape();    }
  282.  
  283. pascal void TEditView::Draw(Rect *area)
  284. {
  285.     void    *link;
  286.     ForEachShapeDo((DoToObject)DrawYourself,link);
  287. }
  288.  
  289.  
  290. pascal void TEditView::Free()
  291. {
  292. }
  293.  
  294. #ifdef qDebug
  295. pascal void TEditView::Fields(pascal void (*DoToField) (StringPtr fieldName,
  296.                         Ptr fieldAddr, short fieldType, void *link), void *link)
  297. {
  298.     DoToField("\pTEditView", nil, bClass, link);
  299.     DoToField("\pfDocument", (Ptr) &fDocument, bObject, link);
  300.     DoToField("\pfShapeList", (Ptr) &fShapeList, bObject, link);
  301.     inherited::Fields(DoToField, link);
  302. }
  303. #endif
  304.  
  305.  
  306. TEditor *gEditor;
  307.  
  308. int main()
  309. {
  310.     InitToolBox();
  311.     if (ValidateConfiguration(&gConfiguration))
  312.     {
  313.         InitUMacApp(8);
  314.         InitUPrinting();
  315.         InitUTEView();
  316.         gEditor = new TEditor(kFileType);
  317.         FailNIL(gEditor);
  318.         gEditor->Run();
  319.     }
  320.     else StdAlert(phUnsupportedConfiguration);
  321.     return 0;
  322. }
  323.